package com.pptv.ads.core.utils;


import com.google.gson.Gson;


public class SerializeUtil {

	private final static Gson gson = new Gson();
	
	public static <T> byte[] serialize(T obj){
		if(obj == null) return null;
		return gson.toJson(obj).getBytes();
		
		
	/*	ByteArrayOutputStream os = new ByteArrayOutputStream();
		HessianOutput ho = new HessianOutput(os);
		try {
			ho.writeObject(obj);
		} catch (IOException e) {
			throw new IllegalStateException(e.getMessage(), e);
		}
		return os.toByteArray();*/
	}

	public static <T> T deserialize(byte[] bytes, Class<T> clazz) {
		if(bytes == null ) return null;
		return gson.fromJson(new String(bytes), clazz);
		
		/*ByteArrayInputStream is = new ByteArrayInputStream(bytes);
		HessianInput hi = new HessianInput(is);
		try {
			return hi.readObject();
		} catch (IOException e) {
			throw new IllegalStateException(e.getMessage(), e);
		}*/
	}
	
}
